Skip to contentSkip to conversation

EXTRA_USERS_PARAMS doesn't work to generate password for root and add new users

DISCUSSION Crane 4 participants 14 messages Aug 22, 2023 – Sep 1, 2023

lore
Share & tools
lore

Crane

author
#0 lore raw

Hello,

I am trying to generate a password for root and add a new user. Here is the code in the image recipe:

IMAGE_FEATURES:remove = "debug-tweaks"
INHERIT += "extrausers"
EXTRA_USERS_PARAMS += "usermod -P root root; useradd -P 2023 crane"

When using "inherit extrausers", there is an error of "usermod command did not succeed."

When checking the parameter, the result is:
EXTRA_USERS_PARAMS=" usermod -P root root; useradd -P 2023 crane; "

The image does requires a password for root, but doesn't generate anything in /etc/shadow and doesn't add new user in /etc/shadow as well.

I am wondering what might be missing. Can anyone give me any clue?

Thanks!
Crane

#1 lore raw
Quoted 13 lines · Crane

Hello,

I am trying to generate a password for root and add a new user. Here is the code in the image recipe:

IMAGE_FEATURES:remove = "debug-tweaks"
INHERIT += "extrausers"
EXTRA_USERS_PARAMS += "usermod -P root root; useradd -P 2023 crane"

When using "inherit extrausers", there is an error of "usermod command did not succeed."

When checking the parameter, the result is:
EXTRA_USERS_PARAMS=" usermod -P root root; useradd -P 2023 crane; "

Quoted 8 lines

The image does requires a password for root, but doesn't generate anything in /etc/shadow and doesn't add new user in /etc/shadow as well.

I am wondering what might be missing. Can anyone give me any clue?

Thanks!
Crane

Hi,

the error could be related to the -P option in useradd command: the option, that allows to pass a cleartext password to the command, is not present anymore in recent useradd versions.

Instead you can use the -p option, that allows to pass an encrypted password. Something like that:

EXTRA_USERS_PARAMS=" usermod -p openssl passwd -6 root root; useradd -P 2023 crane; "

Regards

Signature · 3 lines
Mauro Salvini | KOAN sas | Bergamo - Italia
embedded software engineering
http://KoanSoftware.com
author
#2 lore raw

Thanks Mauro for your input.

I referred two posts from Koan Software in my work. One is to use devtool to modify recipe and another one is to add system service to image. Very clearly explained. Thanks!

Good point. I tried, but in my case it looks still not generating the password and also no new user added.
And I am afraid that the $ symbol in the encrypted password string might prevent it from being applied. I tried to add \ before $ symbol. And it's also not working.

Wondering what else might be still missing.

author
#3 lore raw

Here is the variable value:
EXTRA_USERS_PARAMS=" usermod -p 'openssl passwd -6 root' root; useradd -p 'openssl passwd -6 2023' crane; "

Actually no need to add \ before $ symbol.  \ is already added as below:
EXTRA_USERS_PARAMS=" usermod -p '\$6\$9UMdfjsa9kYD4oQB\$a3jUptBObMgh8palvzovMriEp8X0d/7xHHOj7WdcBKXvhcUvOBOzFTAdl3.NDi.CGwMtpwfB3J6dvxRQN.iUq.' root; useradd -p '\$6\$IfrdWN4tMhCHSL6E\$NS3/r/qO3kSKNh0PVtqmrocLAxbdkUZu3cYg7czkMy9Y42le02G92hgxRVvsFogjCufY4BRdjRdaW77K/kT170' crane; "

#4 lore raw
In reply to Crane
Quoted 6 lines · Crane

Thanks Mauro for your input.

I referred two posts from Koan Software in my work. One is to use devtool to modify recipe and another one is to add system service to image. Very clearly explained. Thanks!

Good point. I tried, but in my case it looks still not generating the password and also no new user added.
And I am afraid that the $ symbol in the encrypted password string might prevent it from being applied. I tried to add \ before $ symbol. And it's also not working.

oh, indeed.

Try with this:

EXTRA_USERS_PARAMS=" usermod -p '$(openssl passwd -6 root)' root; useradd -p '$(openssl passwd -6 2023)' crane; "

Quoted 3 lines

Wondering what else might be still missing.

Signature · 4 lines
Mauro Salvini | KOAN sas | Bergamo - Italia
embedded software engineering
✆:+39 351-9518710
http://KoanSoftware.com
author
#5 lore raw
Quoted 5 lines · Mauro

Try with this:

EXTRA_USERS_PARAMS=" usermod -p '$(openssl passwd -6 root)' root; useradd -p '$(openssl passwd -6 2023)' crane; "

Not working.
Here is the value of the variable becoming:
EXTRA_USERS_PARAMS=" usermod -p '\$(openssl passwd -6 root)' root; useradd -p '\$(openssl passwd -6 2023)' crane; " One \ is added before $ symbol.

#6 lore raw
Quoted 7 lines · Crane

On Tue, Aug 22, 2023 at 11:36 AM, Mauro wrote:

    Try with this:

    EXTRA_USERS_PARAMS=" usermod -p '$(openssl passwd -6 root)' root;
    useradd -p '$(openssl passwd -6 2023)' crane; "

Uh, I'm using this one successfully, on a Yocto Warrior.

Quoted 6 lines

Not working.
Here is the value of the variable becoming:
EXTRA_USERS_PARAMS=" usermod -p '\$(openssl passwd -6 root)' root; useradd -p '\$(openssl passwd -6 2023)' crane; " One \ is added before $ symbol.

Then the \ is added automatically by Yocto? Maybe something has changed in variables parsing...or could be a bug? Don't know, help needed from the experts!

You can put the encrypted password (the result of the "openssl passwd -6 root" command) directly in the variable, taking care to put a "\" before the three "$" contained in the string. Something like this:

EXTRA_USERS_PARAMS=" usermod -p '\$6\$CEM0hANiVS9VXN8N\$Q9XK1KTpq2faq2fNbSRLNeeA4mmQsl8g1Gwl3QnTPlRPb5ljCAa./bbhffcthXxUen4jSFL6HKGQPlHZNQkfA/' root; useradd -p '\$6\$5wVybJkbuowR0iMi\$tnEJEEbXbcRfksKRSt7rjlY1hRERrjqFOlCaa0s1ivISxAHT7MFdcnZvVbRHgkqRSYzA1oLUxtR0LuvDTMPR5/' crane; "

By the way, this approach has the advantage to mask the password.

Signature · 3 lines
Mauro Salvini | KOAN sas | Bergamo - Italia
embedded software engineering
http://KoanSoftware.com
author
#7 lore raw
Quoted 10 lines · Mauro

You can put the encrypted password (the result of the "openssl passwd -6 root" command) directly in the variable, taking care to put a "\" before the three "$" contained in the string. Something like this:

EXTRA_USERS_PARAMS=" usermod -p '\$6\$CEM0hANiVS9VXN8N\$Q9XK1KTpq2faq2fNbSRLNeeA4mmQsl8g1Gwl3QnTPlRPb5ljCAa./bbhffcthXxUen4jSFL6HKGQPlHZNQkfA/' root; useradd -p '\$6\$5wVybJkbuowR0iMi\$tnEJEEbXbcRfksKRSt7rjlY1hRERrjqFOlCaa0s1ivISxAHT7MFdcnZvVbRHgkqRSYzA1oLUxtR0LuvDTMPR5/' crane; "

Tried as well. And a \ is added automatically in front of $, so no need to add it. But still not working. There must be something else missing. Anyway to debug in this case?

#8 lore raw
Quoted 11 lines · Crane
Quoted 7 lines · Mauro

You can put the encrypted password (the result of the "openssl passwd -6 root" command) directly in the variable, taking care to put a "\" before the three "$" contained in the string. Something like this:

EXTRA_USERS_PARAMS=" usermod -p

'\$6\$CEM0hANiVS9VXN8N\$Q9XK1KTpq2faq2fNbSRLNeeA4mmQsl8g1Gwl3QnTPlRPb5ljCAa./bbhffcthXxUen4jSFL6HKGQPlHZNQkfA/'

Quoted 9 lines
Quoted 2 lines

root; useradd -p

'\$6\$5wVybJkbuowR0iMi\$tnEJEEbXbcRfksKRSt7rjlY1hRERrjqFOlCaa0s1ivISxAHT7MFdcnZvVbRHgkqRSYzA1oLUxtR0LuvDTMPR5/'

Quoted 1 line

crane; "

Tried as well. And a \ is added automatically in front of $, so no need to add it. But still not working.
There must be something else missing. Anyway to debug in this case?

From testing I have observed that the extrausers does not work from a recipe, while useradd works correctly from a recipe. The extrausers should work as expected from within the distribution description, so you might want to try that.

For debugging you could print the bitbake variables to screen (-e) and grep on the EXTRA_USERS_PARAMS.

Hope this is will help you solving the issue.

Signature · 6 lines
With kind regards,

Jeffrey Simons

Software Engineer
Royal Boon Edam International B.V.
#9 lore raw
Quoted 24 lines · Jeffrey Simons
Quoted 11 lines · Crane
Quoted 7 lines · Mauro

You can put the encrypted password (the result of the "openssl passwd -6 root" command) directly in the variable, taking care to put a "\" before the three "$" contained in the string. Something like this:

EXTRA_USERS_PARAMS=" usermod -p

'\$6\$CEM0hANiVS9VXN8N\$Q9XK1KTpq2faq2fNbSRLNeeA4mmQsl8g1Gwl3QnTPlRPb5ljCAa./bbhffcthXxUen4jSFL6HKGQPlHZNQkfA/'

Quoted 9 lines
Quoted 2 lines

root; useradd -p

'\$6\$5wVybJkbuowR0iMi\$tnEJEEbXbcRfksKRSt7rjlY1hRERrjqFOlCaa0s1ivISxAHT7MFdcnZvVbRHgkqRSYzA1oLUxtR0LuvDTMPR5/'

Quoted 1 line

crane; "

Tried as well. And a \ is added automatically in front of $, so no need to add it. But still not working.
There must be something else missing. Anyway to debug in this case?

Quoted 5 lines

From testing I have observed that the extrausers does not work from a recipe, while useradd works correctly from a recipe. The extrausers should work as expected from within the distribution description, so you might want to try that.

For debugging you could print the bitbake variables to screen (-e) and grep on the EXTRA_USERS_PARAMS.

See this

https://github.com/YoeDistro/yoe-distro/blob/master/conf/projects/rpi4-64/config.conf#L57-L66

you might try something like that in config metadata e.g. local.conf

Quoted 19 lines

Hope this is will help you solving the issue.

--
With kind regards,

Jeffrey Simons

Software Engineer
Royal Boon Edam International B.V.

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
You automatically follow any topics you start or reply to. View/Reply Online (#60870): https://lists.yoctoproject.org/g/yocto/message/60870
Mute This Topic: https://lists.yoctoproject.org/mt/100887124/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#10 lore raw
Quoted 29 lines · Khem Raj
Quoted 27 lines · Jeffrey Simons
Quoted 11 lines · Crane
Quoted 7 lines · Mauro

You can put the encrypted password (the result of the "openssl passwd -6 root" command) directly in the variable, taking care to put a "\" before the three "$" contained in the string. Something like this:

EXTRA_USERS_PARAMS=" usermod -p

'\$6\$CEM0hANiVS9VXN8N\$Q9XK1KTpq2faq2fNbSRLNeeA4mmQsl8g1Gwl3QnTPlRPb5ljCAa./bbhffcthXxUen4jSFL6HKGQPlHZNQkfA/'

Quoted 9 lines
Quoted 2 lines

root; useradd -p

'\$6\$5wVybJkbuowR0iMi\$tnEJEEbXbcRfksKRSt7rjlY1hRERrjqFOlCaa0s1ivISxAHT7MFdcnZvVbRHgkqRSYzA1oLUxtR0LuvDTMPR5/'

Quoted 1 line

crane; "

Tried as well. And a \ is added automatically in front of $, so no need to add it. But still not working.
There must be something else missing. Anyway to debug in this case?

From testing I have observed that the extrausers does not work from a recipe, while useradd works correctly from a recipe.
The extrausers should work as expected from within the distribution description, so you might want to try that.

Quoted 19 lines
Quoted 2 lines

For debugging you could print the bitbake variables to screen (-e) and grep on the EXTRA_USERS_PARAMS.

See this

https://github.com/YoeDistro/yoe-distro/blob/master/conf/projects/rpi4-64/config.conf#L57-L66

you might try something like that in config metadata e.g. local.conf

Quoted 10 lines

Hope this is will help you solving the issue.

--
With kind regards,

Jeffrey Simons

Software Engineer
Royal Boon Edam International B.V.

Hi all,

I did some tests on a Yocto Kirkstone using qemux86-64.

I can confirm that:

- using extrausers class in local.conf (as pointed out by Khem) works properly

  INHERIT += "extrausers"
  EXTRA_USERS_PARAMS = "useradd -p '$(openssl passwd -6 crane)' crane;"

OR (escaped cyphered password)

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "useradd -p
'\$6\$z6vHqLrwnkHbcf5n\$0Fod3ijjV0XcGLYJm.EcomRXsL63p3ntbmznEjp7FHQq4sDtd/YFcAbw5Dg4/iQAsAyee7YG5/LNTe4nCwxzg1' crane;"

- using extrausers class in image recipe works properly

  inherit extrausers
  EXTRA_USERS_PARAMS = "useradd -p '$(openssl passwd -6 crane)' crane;"

OR (escaped cyphered password)

inherit extrausers
MY_PASSWORD =
"$6$jAB6jLC45xV7v9yY$nZS7WymiLb1152aV51mYDc0RNctmYi9M0xS9bkXUCIafCGQ/EyIp76.kltVKWt5U4YjHkTOGymP7OJ6p9DVpN."
EXTRA_USERS_PARAMS = "useradd -p '${MY_PASSWORD}' crane;"

- using useradd class in a recipe works

inherit useradd
DEPENDS += "openssl-native"
USERADD_PARAM:${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/sh -p
'$(openssl passwd -6 user3)' user3"

OR (escaped cyphered password)

inherit useradd
USERADD_PARAM:${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/sh -p
'\$6\$bblNDDxePa6LNBbE\$3P5MkG2pUFY1TI1A2Y9CXjA83gvnrO7UMQkcWOEOO7MN4ESJHG7wqfiYWOeHPGZSEKM5/3bcMHDsDBfxpZKRv1' user3"

The only thing to pay attention to is to add

DEPENDS += "openssl-native"

in the recipe in case the openssl form is used.

To Crane: please try to build the image and test it, don't stop at Yocto variables analysis step.

regards

[1] https://docs.yoctoproject.org/ref-manual/classes.html?highlight=useradd#extrausers

Signature · 3 lines
Mauro Salvini | KOAN sas | Bergamo - Italia
embedded software engineering
http://KoanSoftware.com
author
#11 lore raw
Quoted 3 lines · Mauro

To Crane: please try to build the image and test it, don't stop at Yocto variables analysis step.

Thanks Mauro so much.

Indeed, it is not relevant the value of the variable, but where it is assigned. It doesn't work to assign these values in image recipe, but works in local.conf.

I am wondering what's the different in assigning the value in different locations. Maybe it is relevant to the building sequence. If it is assigned later, it is useless. Is there any rule to follow? Or it is just from experience?

Another question I think of is how you guys source control local.conf. It looks it might be much different from project to project.

Thanks!
Crane

#12 lore raw
Quoted 10 lines · Crane

On Thu, Aug 24, 2023 at 04:21 AM, Mauro wrote:

To Crane: please try to build the image and test it, don't stop at Yocto variables analysis step.

Thanks Mauro so much.

Indeed, it is not relevant the value of the variable, but where it is assigned. It doesn't work to assign these values in image recipe, but works in local.conf.

extrausers class (and then EXTRA_USERS_PARAMS) works both in image recipe and in local.conf, both with the openssl command and with the ciphered password.

Quoted 2 lines

I am wondering what's the different in assigning the value in different locations. Maybe it is relevant to the building sequence. If it is assigned later, it is useless. Is there any rule to follow? Or it is just from experience?

extrauser class is designed to add or modify users at image level, then it must be used in image recipes or in a .conf file. [1]

useradd class is designed to create users at package level, then it must be used in normal (not image) recipes only. [2]

[1] https://docs.yoctoproject.org/ref-manual/classes.html#extrausers
[2] https://docs.yoctoproject.org/ref-manual/classes.html#useradd

Quoted 4 lines

Another question I think of is how you guys source control local.conf. It looks it might be much different from project to project.

Thanks!
Crane

Signature · 4 lines
Mauro Salvini | KOAN sas | Bergamo - Italia
embedded software engineering
✆:+39 351-9518710
http://KoanSoftware.com
author
#13 lore raw
Quoted 9 lines · Mauro

extrauser class is designed to add or modify users at image level, then it must be used in image recipes or in a .conf file. [1]

useradd class is designed to create users at package level, then it must be used in normal (not image) recipes only. [2]

[1] https://docs.yoctoproject.org/ref-manual/classes.html#extrausers
[2] https://docs.yoctoproject.org/ref-manual/classes.html#useradd

Thanks Manro for sharing these links. Now I see a big pool of classes that can be used.

Eventually I found that why it doesn't work for me to add EXTRA_USER_PARAMS in image recipe is that I used this line: INHERIT += "extrausers" instead of this line: inherit extrausers
to use the class extrausers.

But at the beginning there was an error when using "inherit extrauser". Now it works fine. I couldn't figure out why. But anyway it works this way now.

Regards,
Crane